<template>
	<view>
		<view class="first-block">
			<view class="top-block">
				<bubble-block></bubble-block>
				<view class="circle-block">
					<view class="big_circle"></view>
					<view class="small_circle"></view>
					<view class="content">
						<view>今日发电</view>
						<view style="font-size: 36upx;">
							{{(parseFloat(summary.rfdl.replace(new RegExp(',',"gm"),''))).toFixed(2)}}
						</view>
						<view>KWh</view>
					</view>
				</view>
				<view class="right">
					<view class="weather">
						<u-image src="/static/home/icon_rain.png" width="30" height="28" mode="aspectFit" />
						<span class="txt">{{vuex_weather.dayType}} {{vuex_weather.wendu}}℃</span>
					</view>
					<view class="right-data">
						<view class="item-block">
							<view class="icon-item">
								<u-image width="68" height="68" src="/static/home/icon_this_month.png"
									mode="aspectFit" />
							</view>
							<view class="data-item">
								<view class="title">当月发电量（MWh）</view>
								<view class="value">
									{{(parseFloat(summary.yfdl.replace(new RegExp(',',"gm"),''))/1000).toFixed(2)}}
								</view>
							</view>
						</view>
						<view class="item-block">
							<view class="icon-item">
								<u-image width="68" height="68" src="/static/home/icon_total.png" mode="aspectFit" />
							</view>
							<view class="data-item">
								<view class="title">累计发电量（MWh）</view>
								<view class="value">
									{{(parseFloat(summary.ljdl.replace(new RegExp(',',"gm"),''))/1000).toFixed(2)}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="bottom-block">
				<view class="inner-block">
					<u-image src="/static/home/current_power.png" width="32" height="32" />
					<span style="margin:0 12upx">当前功率</span>
					<span>{{(parseFloat(summary.ssgl.replace(new RegExp(',',"gm"),''))).toFixed(2)}}</span>
					<span>KW</span>
				</view>
			</view>
		</view>

		<u-gap height="22" bg-color="#F7F8FA" />

		<view class="second-block">
			<view class="item-block">
				<u-image src="/static/home/icon_0.png" width="78" height="78" />
				<view class="value-block">
					{{(parseFloat(summary.zjrl.replace(new RegExp(',',"gm"),''))).toFixed(2)}}
				</view>
				<view class="unit-name">装机容量(kwp)</view>
			</view>
			<navigator hover-class="none" url="/pages/station/index" open-type="switchTab">
				<view class="item-block">
					<u-image src="/static/home/icon_1.png" width="78" height="78" />
					<view class="value-block">{{summary.zdzs}}</view>
					<view class="unit-name">站点数量(个)</view>
				</view>
			</navigator>
			<navigator hover-class="none" url="/pages/warning/index" open-type="switchTab">
				<view class="item-block">
					<u-image src="/static/home/icon_2.png" width="78" height="78" />
					<view class="value-block">
						{{parseInt(summary.yxgj) + parseInt(summary.txgj) + parseInt(summary.ljgj)}}
					</view>
					<view class="unit-name">告警信息（条）</view>
				</view>
			</navigator>
		</view>

		<u-gap height="22" bg-color="#F7F8FA" />

		<ucharts-block ref="chartBlock" />

		<u-gap height="22" bg-color="#F7F8FA" />

		<env-block :data='summary.ljdl' />

		<u-gap height="22" bg-color="#F7F8FA" />
		<view class="fifth-block">
			<view class="top-block">
				<view class="left-block">
					<view class="block-title">
						<u-image src="/static/home/icon_weather.png" width="38" height="38" />
						<view class="txt">气象数据</view>
					</view>
					<view class="header-block">
						<view class="title">{{vuex_weather.city}} {{vuex_weather.dayType}} {{vuex_weather.wendu}}℃
						</view>
					</view>
				</view>
				<view class="right-block">
					<view class="circle-track">
						<u-image class='sun' src="/static/home/sun.png" mode="aspectFit" width="40" height="38" />
						<view class="sun-time-left">
							{{vuex_weather.sunrise_1}}
						</view>
						<view class="sun-time-right">
							{{vuex_weather.sunset_1}}
						</view>
					</view>
				</view>
			</view>
			<view class="bottom-block">
				<view class="item-block">
					<view class="label">风向：</view>
					<view>{{vuex_weather.fengxiang}}</view>
				</view>
				<view class="item-block label">日照时长</view>
				<view class="item-block ">
					<view class="label">风力：</view>
					<view>{{vuex_weather.fengli}}</view>
				</view>
				<view class="item-block value">{{sunshineDuration}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		loadWeather
	} from '../../common/weather.js'
	import uchartsBlock from '../../components/ucharts-block.vue'
	import envBlock from '../../components/env-block.vue'
	import bubbleBlock from '../../components/bubble-block.vue'
	export default {
		components: {
			uchartsBlock,
			envBlock,
			bubbleBlock
		},
		data() {
			return {
				summary: {
					rfdl: "0",
					yfdl: "0",
					ljdl: "0",
					ssgl: "0",
					zjrl: "0"
				}
			}
		},
		onLoad() {
			this.loadSummaryInfo()
			loadWeather(this)
		},
		onReady() {
			this.$refs.chartBlock.loadChartInfo()
		},
		onPullDownRefresh() {
			this.loadSummaryInfo()
			this.$refs.chartBlock.loadChartInfo()
		},
		computed: {
			// 计算日照时长
			sunshineDuration() {
				if (this.vuex_weather.sunrise_1 && this.vuex_weather.sunset_1) {
					let sunrise_hour = this.vuex_weather.sunrise_1.substring(0, 2)
					console.log('sunrise_hour=', sunrise_hour)
					let sunrise_minute = this.vuex_weather.sunrise_1.substring(3, 5)
					console.log('sunrise_minute=', sunrise_minute)
					let sunrise_total_minite = parseInt(sunrise_hour) * 60 + parseInt(sunrise_minute)
					console.log('sunrise_total_minite=', sunrise_total_minite)

					let sunset_hour = this.vuex_weather.sunset_1.substring(0, 2)
					console.log('sunset_hour=', sunset_hour)
					let sunset_minute = this.vuex_weather.sunset_1.substring(3, 5)
					console.log('sunset_minute=', sunset_minute)
					let sunset_total_minite = parseInt(sunset_hour) * 60 + parseInt(sunset_minute)
					console.log('sunset_total_minite=', sunset_total_minite)
					let duration_hour = Math.floor((sunset_total_minite - sunrise_total_minite) / 60)
					console.log('duration_hour=', duration_hour)
					let duration_minute = Math.floor((sunset_total_minite - sunrise_total_minite) % 60)
					console.log('duration_minute=', duration_minute)
					return `${duration_hour}小时 ${duration_minute}分钟`
				}
				return 0;
			}
		},
		methods: {
			loadSummaryInfo() {
				this.$u.api.getSummaryInfo().then(res => {
					if (res.error_code === 0) this.summary = res.data
				}).finally(() => {
					uni.stopPullDownRefresh()
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.first-block {
		height: 442upx;
		padding: 16upx 42upx 28upx 42upx;
		background: url(../../static/home/top_bg.png);
		background-size: cover;

		.top-block {
			display: flex;
			justify-content: space-between;

			.circle-block {
				padding: 8upx;
				position: relative;
				border-radius: 50%;
				border: 4px solid #65ebf2;

				.big_circle {
					overflow: hidden;
					width: 300upx;
					height: 300upx;
					z-index: -1;
					position: absolute;
					border-radius: 50%;
					background-image: radial-gradient(circle, #00a848 50%, #008a33);
				}

				.small_circle {
					position: absolute;
					width: 290upx;
					height: 290upx;
					border-radius: 50%;
					border-top: 8upx solid #aff3d5;
					// border-bottom: 8upx solid #aff3d5;
					// background:red;
					margin-top: 5upx;
					margin-left: 4upx;
					/* 控制边框颜色渐变 */
					animation: animate 3s linear infinite;
				}


				@keyframes animate {
					0% {
						transform: rotate(0deg);
					}

					100% {
						transform: rotate(360deg);
					}
				}


				.content {
					z-index: 99;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					color: #fff;
					font-size: 24upx;
					line-height: 50upx;
					width: 300upx;
					height: 300upx;
				}
			}

			.right {
				.weather {
					font-size: 24upx;
					font-weight: 400;
					color: #4290F2;
					text-align: right;
					display: flex;
					align-items: center;
					justify-content: flex-end;

					.txt {
						margin-left: 12upx;
					}
				}

				.right-data {
					.item-block {
						display: flex;
						margin-top: 46upx;

						.icon-item {}

						.data-item {
							margin-left: 16upx;

							.title {
								font-size: 24upx;
								color: #666;
							}

							.value {
								font-size: 28upx;
								color: #000;
								font-weight: bold;
							}
						}
					}
				}
			}
		}

		.bottom-block {
			display: flex;
			justify-content: center;
			margin-top: 12upx;

			.inner-block {
				height: 60upx;
				background: #fff;
				box-shadow: 0px 0px 20px 0px rgba(66, 144, 242, 0.16);
				border-radius: 30upx;
				display: flex;
				padding: 0 38upx;
				align-items: center;
			}
		}
	}

	.second-block {
		height: 248upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 40upx;

		.item-block {
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 180upx;

			.value-block {
				font-size: 30upx;
				font-weight: bold;
				color: #4290F2;
				margin-top: 10upx;
			}

			.unit-name {
				font-size: 24upx;
				font-weight: 400;
				color: #999999;
				margin-top: 10upx;
				width: 200upx;
				text-align: center;
			}
		}
	}

	.third-block {
		// height: 600upx;
		padding: 28upx 32upx;
		// background: red;

		.condition-block {
			margin: 34upx 0;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.left {
				width: 330upx;
				display: flex;
				background-color: #EBF4FF;
				height: 60upx;
				color: #333;
				font-size: 28upx;
				border-radius: 35upx;
				border: 1upx solid #378FFA;

				.first-item {
					border-top-left-radius: 36upx;
					border-bottom-left-radius: 36upx;
				}

				.item-center {
					border-left: 1upx solid #378FFA;
				}

				.item {
					line-height: 62upx;
					width: 110upx;
					text-align: center;
				}

				.last-item {
					border-top-right-radius: 36upx;
					border-bottom-right-radius: 36upx;
					border-left: 1upx solid #378FFA;
				}

				.active {
					background-color: #378FFA;
					color: #fff;
				}
			}

			.right {
				width: 198upx;
				height: 60upx;
				border-radius: 40upx;
				border: 1px solid #378FFA;
				text-align: center;
				line-height: 60upx;
				font-size: 24upx;
				font-weight: 400;
				color: #378FFA;
				display: flex;
				justify-content: space-around;
				padding: 0 15upx;
			}
		}

		.chart-box {
			width: 100%;
			// height: 500upx;
			// background: green;
		}
	}

	.fifth-block {
		padding: 28upx 32upx 60upx 32upx;

		.top-block {
			display: flex;
			justify-content: space-between;

			.left-block {
				.header-block {
					margin-top: 42upx;
					display: flex;
					align-items: center;

					.title {
						margin-left: 28upx;
						font-weight: bold;
						font-size: 36upx;
						color: #000;
					}
				}
			}

			.right-block {
				.circle-track {
					border-left: 2upx dotted #999;
					border-right: 2upx dotted #999;
					border-top: 2upx dotted #999;
					width: 168upx;
					height: 84upx;
					border-top-left-radius: 168upx;
					border-top-right-radius: 168upx;
					// background-color: green;
					margin-right: 68upx;
					position: relative;

					.sun {
						position: absolute;
						right: 20upx;
						top: -8upx;
					}

					.sun-time-left {
						position: absolute;
						bottom: -40upx;
						left: -40upx;
						font-size: 28upx;
						color: #999;
					}

					.sun-time-right {
						position: absolute;
						bottom: -40upx;
						right: -40upx;
						font-size: 28upx;
						color: #999;
					}
				}
			}
		}

		.bottom-block {
			display: flex;
			flex-wrap: wrap;
			margin-top: 42upx;

			.item-block {
				width: 50%;
				margin-bottom: 12upx;
				display: flex;
				padding-left: 70upx;
			}

			.label {
				color: #999;
				font-size: 28upx;
			}

			.value {
				font-size: 28upx;
				color: #333;
			}
		}
	}

	.block-title {
		display: flex;
		align-items: center;

		.txt {
			margin-left: 10upx;
			font-weight: 400;
			font-size: 28upx;
			color: #999;
		}
	}
</style>
